package cn.edu.neusoft.maxingxin231.yuejian06.Adapter;

import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;

import com.squareup.picasso.Picasso;

import java.util.List;

import cn.edu.neusoft.maxingxin231.yuejian06.Activity.TrainDetailActivity;
import cn.edu.neusoft.maxingxin231.yuejian06.Bean.TrainBean;

public class AdvanceAdapter extends Base2Adapter<TrainBean> {
    String id;

    public AdvanceAdapter(Context context, List<TrainBean> items, int layoutResource) {
        super(context, items, layoutResource);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, final int position) {
        TrainBean trainBean = items.get(position);
        if(trainBean==null) return;
        final ClubViewHolder clubViewHolder = (ClubViewHolder) holder;

        final String train_id=items.get(position).getTrain_id();
        final String train_name=items.get(position).getTrain_name();
        final String train_intro=items.get(position).getTrain_intro();
        final String train_type=items.get(position).getTrain_type();
        final String train_time=items.get(position).getTrain_time();
        final String train_address=items.get(position).getTrain_address();
        final String train_price=items.get(position).getTrain_price();
        final String train_pic=items.get(position).getTrain_pic();

        clubViewHolder.c_tv1.setText(train_name);
        clubViewHolder.c_tv2.setText(train_type);
        Picasso.with(context).load("http://10.0.2.2:80/yuejian14/public/static/trains/"+items.get(position).getTrain_pic()).into(clubViewHolder.c_img1);
        clubViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //条目点击事件
                Log.i("TEST","onClick");
                Intent intent = new Intent(context,TrainDetailActivity.class);
                intent.putExtra("id",id);
                intent.putExtra("train_name",train_name);
                intent.putExtra("train_pic",train_pic);
                intent.putExtra("train_intro",train_intro);
                intent.putExtra("train_type",train_type);
                intent.putExtra("train_time",train_time);
                intent.putExtra("train_address",train_address);
                intent.putExtra("train_price",train_price);
                context.startActivity(intent);
            }
        });
    }
    public void setList(List<TrainBean> list){
        this.items = list;
        notifyDataSetChanged();
    }
}
